<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>用户管理</title>
</head>

<body>

<div class="main-content-inner">
    <!-- #section:basics/content.breadcrumbs -->
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="ace-icon fa fa-home home-icon"></i>
                <a href="${ctx}/welcome">主页</a>
            </li>
            <li class="active">用户</li>
        </ul><!-- /.breadcrumb -->

    </div>
    <!-- /section:basics/content.breadcrumbs -->

    <div class="page-content">

        <c:if test="${not empty message}">
            <div id="message" class="alert alert-success">
                <button data-dismiss="alert" class="close">×</button>
                    ${message}</div>
        </c:if>

        <div class="page-header">
            <h1>
                用户
                <small>
                    <i class="ace-icon fa fa-angle-double-right"></i>
                    <c:choose>
                        <c:when test="${action eq 'create' }">
                            新增用户
                        </c:when>
                        <c:otherwise>
                            更新用户
                        </c:otherwise>
                    </c:choose>
                </small>
            </h1>
        </div><!-- /.page-header -->

        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="row">
                    <div class="col-xs-12">

                        <form id="inputForm" action="${ctx}/user/${action}" method="post" class="form-horizontal">
                            <input type="hidden" name="id" id="id" value="${user.id}"/>
                            <!-- 								<input type="hidden" name="status" value=""/> -->
                            <!-- 								<input type="hidden" name="userType" value="2"/> -->

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 账号: </label>
                                <div class="col-sm-9">
                                    <input type="text" maxlength="15" autocomplete="off" id="user_loginName"
                                           <c:if test="${action eq 'update'}">readonly="readonly"</c:if>
                                           name="loginName" value="${user.loginName}" placeholder="账号"
                                           class="col-xs-10 col-sm-5 required"/>
                                </div>
                            </div>
                            <c:if test="${action eq 'create'}">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                                        用户密码: </label>
                                    <div class="col-sm-9">
                                        <input type="text" autocomplete="off" id="user_plainPassword"
                                               name="plainPassword" readonly="readonly" value="123456"
                                               placeholder="用户密码" class="col-xs-10 col-sm-5 required"/>
                                    </div>
                                </div>
                            </c:if>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                                    用户姓名: </label>
                                <div class="col-sm-9">
                                    <input type="text" maxlength="10" autocomplete="off" id="user_name" name="name"
                                           value="${user.name}" placeholder="用户姓名" class="col-xs-10 col-sm-5 required"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">用户电话: </label>
                                <div class="col-sm-9">
                                    <input type="text" maxlength="11" autocomplete="off" id="user_mobile" name="mobile"
                                           value="${user.mobile}" placeholder="用户电话"
                                           class="col-xs-10 col-sm-5 required"/>
                                </div>
                            </div>
                            <!-- start 授予角色 -->
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                                    所属角色: </label>
                                <div class="col-sm-4">
                                    <select class="form-control required" id="roleid" name="roleid">
                                        <option value="0">请选择</option>
                                        <c:forEach items="${roles}" var="role">
                                            <option value="${role.id}"
                                                    <c:if test="${role.id == user.role.id}">selected="selected"</c:if> >${role.rolename}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>

                            <!-- end 授予角色-->
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">用户类型: </label>
                                <div class="col-sm-2">
                                    <select class="chosen-select form-control" id="user_type" name="type"
                                            data-placeholder="请选择用户类型">
                                        <%-- 											<option value="user" <c:if test="${user.type eq 'user' }">selected="selected"</c:if>>普通用户</option> --%>
                                        <option value="admin"
                                                <c:if test="${user.type eq 'amdin' }">selected="selected"</c:if>>管理员
                                        </option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">是否可用: </label>
                                <div class="col-sm-2">
                                    <select class="chosen-select form-control" id="user_deltag" name="deltag"
                                            data-placeholder="请选择该用户是否可用">
                                        <option value="0"
                                                <c:if test="${user.deltag eq '0' }">selected="selected"</c:if>>可用
                                        </option>
                                        <option value="1"
                                                <c:if test="${user.deltag eq '1' }">selected="selected"</c:if>>不可用
                                        </option>
                                    </select>
                                </div>
                            </div>

                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button id="submit_btn" class="btn btn-info" type="submit">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        提交
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button id="cancel_btn" class="btn" type="reset" onclick="history.back()">
                                        <i class="ace-icon fa fa-undo bigger-110"></i>
                                        返回
                                    </button>
                                </div>
                            </div>

                        </form>

                    </div><!-- /.span -->
                </div><!-- /.row -->
            </div>
        </div>

    </div><!-- /.page-content -->
</div>


<!-- inline scripts related to this page -->

<script src="${ctx}/static/js/jquery.validate.min.js"></script>
<script src="${ctx}/static/js/messages_bs_zh.js"></script>

<script>
    $(document).ready(function () {
        //聚焦第一个输入框
        $("#user_loginName").focus();

        // 手机号码验证
        jQuery.validator.addMethod("isMobile", function (value, element) {
            var length = value.length;
            return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value));
        }, "请正确填写您的手机号码。");

        jQuery.validator.addMethod("checkcount", function (value, element) {
            var count = /^[a-zA-Z0-9]{1,}$/;    //电话号码格式010-12345678
            return this.optional(element) || (count.test(value));
        }, "账号只能输入字母和数字");

        //为inputForm注册validate函数
        $("#inputForm").validate({
            onsubmit: true,
            rules: {
                idCard: {
                    maxlength: 18,
                    minlength: 18
                },
                name: {
                    rangelength: [2, 10]
                },
                mobile: {
                    rangelength: [11, 11],
                    isMobile: true,
                    remote: "${ctx}/user/checkadmintel?userId=" + $("#id").val()
                },
                loginName: {
                    checkcount: true,
                    rangelength: [4, 15],
                    remote: "${ctx}/user/checkLoginName?userId=" + $("#id").val()
                }
            },
            messages: {
                mobile: {
                    rangelength: "请输入11位手机号码",
                    isMobile: "请输入正确的手机号码",
                    remote: "手机号已存在"
                },
                loginName: {
                    rangelength: "请输入4-15位长度的数字或字符串",
                    remote: "用户账号已存在"
                }
            }
        });

    });

    function alerta() {
        document.getElementById('inputForm').submit();
    }
</script>
</body>
</html>
